package com.toidep.fragment.mains;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.toidep.R;
import com.toidep.activities.MainActivity;
import com.toidep.base.BaseFragment;
import com.toidep.preference.SharePreference;

public class MenuFragment extends BaseFragment implements OnClickListener {

	private View view;
	private MainActivity mainActivity;
	
	private LinearLayout buttonHome, buttonModel, buttonVideo, buttonAlbum;
	private LinearLayout buttonIntro, buttonNews;//, buttonStory, buttonEvent;
	private LinearLayout buttonLogin, buttonUser, buttonLogout, buttonUserInfo, buttonPayment;
	private LinearLayout buttonFree, buttonUpdate, buttonRegister;
	private TextView label_support;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

		view = inflater.inflate(R.layout.layout_slidebar_left, container, false);

		mainActivity = (MainActivity) getActivity();

		initComponents();

		return view;
	}

	private void initComponents() {
		
		buttonHome = (LinearLayout) view.findViewById(R.id.layoutButtonHome);
		buttonHome.setOnClickListener(this);
		buttonFree = (LinearLayout) view.findViewById(R.id.layoutButtonFree);
		buttonFree.setOnClickListener(this);
		buttonUpdate = (LinearLayout) view.findViewById(R.id.layoutButtonUpdate);
		buttonUpdate.setOnClickListener(this);
		buttonModel = (LinearLayout) view.findViewById(R.id.layoutButtonModel);
		buttonModel.setOnClickListener(this);
		buttonVideo = (LinearLayout) view.findViewById(R.id.layoutButtonVideo);
		buttonVideo.setOnClickListener(this);
		buttonAlbum = (LinearLayout) view.findViewById(R.id.layoutButtonAlbum);
		buttonAlbum.setOnClickListener(this);
		buttonIntro = (LinearLayout) view.findViewById(R.id.layoutButtonIntro);
		buttonIntro.setOnClickListener(this);
		buttonNews = (LinearLayout) view.findViewById(R.id.layoutButtonNews);
		buttonNews.setOnClickListener(this);
//		buttonStory = (LinearLayout) view.findViewById(R.id.layoutButtonStory);
//		buttonStory.setOnClickListener(this);
//		buttonEvent = (LinearLayout) view.findViewById(R.id.layoutButtonEvent);
//		buttonEvent.setOnClickListener(this);
		
		label_support = (TextView) view.findViewById(R.id.label_support);
		buttonLogin = (LinearLayout) view.findViewById(R.id.layoutButtonLogin);
		buttonLogin.setOnClickListener(this);
		buttonUser = (LinearLayout) view.findViewById(R.id.layoutButtonUser);
		buttonLogout = (LinearLayout) view.findViewById(R.id.layoutButtonLogout);
		buttonLogout.setOnClickListener(this);
		buttonUserInfo = (LinearLayout) view.findViewById(R.id.layoutButtonUserInfo);
		buttonUserInfo.setOnClickListener(this);
		buttonPayment = (LinearLayout) view.findViewById(R.id.layoutButtonPayment);
		buttonPayment.setOnClickListener(this);
		buttonRegister = (LinearLayout) view.findViewById(R.id.layoutButtonRegister);
		buttonRegister.setOnClickListener(this);
		changeButtonLoginLabel();
	}
	
	public void changeButtonLoginLabel() {
		boolean loginStatus = SharePreference.getInstance(mainActivity).getLoginStatus();
		if (loginStatus) {
			buttonRegister.setVisibility(View.GONE);
			buttonLogin.setVisibility(View.GONE);
			buttonUser.setVisibility(View.VISIBLE);
//			label_support.setText(R.string.label_account);
			boolean isPlaymentApprove = SharePreference.getInstance(mainActivity).getPaymentApprove();
			if (isPlaymentApprove) {
				buttonPayment.setVisibility(View.VISIBLE);
			} else {
				buttonPayment.setVisibility(View.GONE);
			}
		} else {
			buttonRegister.setVisibility(View.VISIBLE);
			buttonLogin.setVisibility(View.VISIBLE);
			buttonUser.setVisibility(View.GONE);
//			label_support.setText(R.string.label_account);
		}
	}
	

	@Override
	public void onClick(View view) {
		mainActivity.doClick(view.getId());
	}

	
}
